
package com.feib.soeasy.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import com.feib.soeasy.dao.PaymentConfigDao;
import com.feib.soeasy.model.LabelValue;
import com.feib.soeasy.model.PaymentConfig;
import com.feib.soeasy.pagination.PaginatedList;
import com.feib.soeasy.service.PaymentConfigService;


/**
 * @title (#)PaymentConfigServiceImpl.java<br>
 * @description <br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2011/3/7 create by Jimmy Liu<br>
 */

import org.springframework.stereotype.Service;

@Service("paymentConfigService")
public class PaymentConfigServiceImpl extends BaseServiceImpl implements PaymentConfigService {

    @Resource(name = "paymentConfigDao")
    private PaymentConfigDao paymentConfigDao;
    
    /* (non-Javadoc)
     * @see com.feib.soeasy.service.PaymentConfigService#queryByPaymentConfig(com.feib.soeasy.model.PaymentConfig, com.feib.soeasy.pagination.PaginatedList)
     */
    @Override
    public PaginatedList<PaymentConfig> queryByPaymentConfig(PaymentConfig paymentConfig, PaginatedList<PaymentConfig> paginationConfig) {
        return paymentConfigDao.queryByPaymentConfig(paymentConfig, paginationConfig);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.PaymentConfigService#queryByPk(java.lang.Long)
     */
    @Override
    public PaymentConfig queryByPk(Long paymentConfigPk) {
        return paymentConfigDao.findByPk(paymentConfigPk);
    }

    /* 
     * (non-Javadoc)
     * @see com.feib.soeasy.service.PaymentConfigService#isDuplicateConfigNo(java.lang.String, java.lang.Long)
     */
    @Override
    public boolean isDuplicateConfigNo(String configNo, Long groupPk) {
        return null != paymentConfigDao.findByConfigNo(configNo, groupPk);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.PaymentConfigService#addPaymentConfig(com.feib.soeasy.model.PaymentConfig)
     */
    @Override
    public PaymentConfig addPaymentConfig(PaymentConfig paymentConfig) {
        return paymentConfigDao.save(paymentConfig);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.PaymentConfigService#save(com.feib.soeasy.model.PaymentConfig)
     */
    @Override
    public PaymentConfig save(PaymentConfig paymentConfig) {
        return paymentConfigDao.save(paymentConfig);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.PaymentConfigService#deletePaymentConfig(com.feib.soeasy.model.PaymentConfig)
     */
    @Override
    public void deletePaymentConfig(PaymentConfig paymentConfig) {
        this.paymentConfigDao.deleteById(paymentConfig.getPaymentConfigPk());
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.PaymentConfigService#findLabelValueByPaymentConfig(com.feib.soeasy.model.PaymentConfig)
     */
    @Override
    public List<LabelValue> findLabelValueByPaymentConfig(PaymentConfig paymentConfig) {
        List<LabelValue> result = new ArrayList<LabelValue>();
        
        List<PaymentConfig> paymentConfigs = paymentConfigDao.queryForListByPaymentConfig(paymentConfig);
        
        for(PaymentConfig p : paymentConfigs)
        {
            LabelValue lv = new LabelValue();
            lv.setValue(p.getConfigNo());
            lv.setLabel(p.getConfigNo() + " - " + p.getConfigName());
            result.add(lv);
        }
        
        paymentConfigs.clear();
        paymentConfigs = null;
        
        return result;
    }

}
